cmake_minimum_required(VERSION 2.6)
project(wxQoole)

# Check the build type
if (CMAKE_BUILD_TYPE STREQUAL "")
	# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
	# differentiation between debug and release builds.
	set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

if(WIN32)
	#set(COMMON_LIBRARIES)
endif(WIN32)

if(UNIX)
	set(COMMON_LIBRARIES dl pthread)
endif(UNIX)

set(CMAKE_DEBUG_POSTFIX "_d")
#set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist")
set(EXECUTABLE_OUTPUT_PATH "${wxQoole_BINARY_DIR}/dist")
set(LIBRARY_OUTPUT_PATH "${wxQoole_BINARY_DIR}/dist")
set(COMMON_LIBRARIES ${COMMON_LIBRARIES} GL GLU)

# Find wxWidgets
find_package(wxWidgets REQUIRED base core adv aui gl xml xrc richtext html adv core base)
include(${wxWidgets_USE_FILE})

if(NOT WXWIDGETS_FOUND)
    message(SEND_ERROR "Failed to find wxWidgets")
endif()

# Find DevIL
find_package(DevIL)

if(IL_FOUND)
	add_definitions(-DUSE_DEVIL)
	include_directories(${IL_INCLUDE_DIR})
endif()

# Add precompiled header support.
#include(PCHSupport.cmake)
include(PCH_GCC4_v2.cmake)
# Add include directories
include_directories(
    ${CMAKE_CURRENT_BINARY_DIR}
	.
	Basic
	Interface
	Interface2
	Loaders
	Objects
	Game
    Qoole
    Render
    ${CMAKE_CURRENT_BINARY_DIR}
)

set(Basic_SRC
	Basic/LCommon.cpp
	Basic/Math3D.cpp
)

set(Objects_SRC
	Objects/Entity.cpp
	Objects/EntList.cpp
	Objects/Game.cpp
	Objects/Geometry.cpp
	Objects/Objects.cpp
	Objects/Texture.cpp
)

set(Interface_SRC
	Interface/QCompile.cpp
	Interface/QConf2DView.cpp
	Interface/QConf3DView.cpp
	Interface/QConfDraw.cpp
	Interface/QConfGames.cpp
	Interface/QConfGeneral.cpp
	Interface/QConfSheet.cpp
	Interface/QChildFrame.cpp
	Interface/QDraw.cpp
	Interface/QDrawVir.cpp
	Interface/QDrawWX.cpp
	Interface/QDrawOGL.cpp
	Interface/QEntSel.cpp
	Interface/QHollowPrompt.cpp
	Interface/QMainFrame.cpp
	Interface/QProcessWindow.cpp
	Interface/QPropEntity.cpp
	Interface/QPropFile.cpp
	Interface/QPropObject.cpp
	Interface/QPropSheet.cpp
	Interface/QPropSheetPage.cpp
	Interface/QPropTexture.cpp	
	Interface/QQuadFrame.cpp
	Interface/QTextureManager.cpp
	Interface/QTexturePanel.cpp
	Interface/QTextureView.cpp	
	Interface/QTreeView.cpp
	Interface/QView.cpp
	Interface/QViewPanel.cpp
)

set(Interface2_SRC
	Interface2/FloatValidator.cpp
	Interface2/IntValidator.cpp
	Interface2/ProgressWindow.cpp
)

set(Game_SRC
	Game/HalfLife.cpp
	Game/Heretic2.cpp
	Game/Hexen2.cpp
	Game/MapIO.cpp
	Game/Quake.cpp
	Game/Quake2.cpp
	Game/paks2wad.cpp
	Game/Sin.cpp
	Game/XmlGame.cpp
)

set(Render_SRC
	Render/Clip.cpp
	Render/Selector.cpp
	Render/View.cpp
)

set(Loaders_SRC
	Loaders/DevILLoader.cpp
	Loaders/TextureLoader.cpp
)

set(Qoole_SRCS
	${Basic_SRC}
	${Objects_SRC}
	${Interface_SRC}
	${Interface2_SRC}
	${Game_SRC}
	${Render_SRC}
	${Loaders_SRC}
	
    Qoole/Qoole.cpp
    Qoole/QooleDoc.cpp
    Qoole/QooleDocManager.cpp
    Qoole/QooleOp.cpp
    Qoole/QooleView.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/wxQoole.xrc.cpp
)

# Build the resources.
add_custom_command(
  OUTPUT wxQoole.xrc.cpp 
  COMMAND wxrc -c -o ${CMAKE_CURRENT_BINARY_DIR}/wxQoole.xrc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxQoole.xrc
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/wxQoole.xrc
)

ADD_PCH_RULE(stdafx.h Qoole_SRCS)
add_executable(wxQoole ${Qoole_SRCS})
target_link_libraries(wxQoole ${COMMON_LIBRARIES} ${wxWidgets_LIBRARIES} ${IL_LIBRARIES} ${ILU_LIBRARIES})

# Copy dist files.
add_subdirectory(data)

